package cn.itsource.hrm.web.controller;

import cn.itsource.hrm.query.CourseQuery;
import cn.itsource.hrm.repository.CourseDocTORepository;
import cn.itsource.hrm.service.ISearcherCourseService;
import cn.itsource.hrm.to.CourseDocTO;
import cn.itsource.hrm.util.AjaxResult;
import cn.itsource.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/es")
public class SearcherController {

    @Autowired
    private CourseDocTORepository courseDocTORepository;

    @Autowired
    private ISearcherCourseService courseService;

    /**
     * 提供一个课程发布的API
     */
    @RequestMapping("/publish")
    @PreAuthorize("hasAuthority('es:online')")
    public AjaxResult onLineCourse(@RequestBody CourseDocTO courseTO){
        courseDocTORepository.save(courseTO);
        return AjaxResult.me();
    }

    /**
     * 提供一个课程发布的API
     */
    @RequestMapping("/searchCourse")
    public AjaxResult searchCourse(@RequestBody CourseQuery query){
        // 和前台做交互对象一般是Vo 或者直接就是Doc
        PageList<CourseDocTO> pageList = courseService.searchCourse(query);
        return AjaxResult.me().setResultObj(pageList);
    }
}
